package com.zhoukai.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhoukai.dto.InventoryLogDto;
import com.zhoukai.vo.DataGridView;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhoukai.domain.InventoryLog;
import com.zhoukai.mapper.InventoryLogMapper;
import com.zhoukai.service.InventoryLogService;
/**
 * Created with IntelliJ IDEA.
 * @Author: zk
 * @Date: 2022/02/10/13:54
 * @Description: 
 */
@DubboService
public class InventoryLogServiceImpl implements InventoryLogService{
    @Autowired
    private InventoryLogMapper inventoryLogMapper;

    @Override
    public DataGridView listInventoryLogForPage(InventoryLogDto inventoryLogDto) {
        Page<InventoryLog> page=new Page<>(inventoryLogDto.getPageNum(),inventoryLogDto.getPageSize());
        this.inventoryLogMapper.selectPage(page, Wrappers.lambdaQuery(InventoryLog.class)
            .like(StringUtils.isNotBlank(inventoryLogDto.getPurchaseId()),InventoryLog::getPurchaseId,inventoryLogDto.getPurchaseId())
            .like(StringUtils.isNotBlank(inventoryLogDto.getMedicinesName()),InventoryLog::getMedicinesName,inventoryLogDto.getMedicinesName())
            .eq(StringUtils.isNotBlank(inventoryLogDto.getMedicinesType()),InventoryLog::getMedicinesType,inventoryLogDto.getMedicinesType())
            .eq(StringUtils.isNotBlank(inventoryLogDto.getPrescriptionType()),InventoryLog::getPrescriptionType,inventoryLogDto.getPrescriptionType())
            .eq(StringUtils.isNotBlank(inventoryLogDto.getProducterId()),InventoryLog::getProducterId,inventoryLogDto.getProducterId())
            .ge(inventoryLogDto.getBeginTime()!=null,InventoryLog::getCreateTime,inventoryLogDto.getBeginTime())
            .le(inventoryLogDto.getEndTime()!=null,InventoryLog::getCreateTime,inventoryLogDto.getEndTime())
            .orderByDesc(InventoryLog::getCreateTime)
        );
        return new DataGridView(page.getTotal(), page.getRecords());
    }
}
